#define _CRT_SECURE_NO_WARNINGS
#include "stack.h"

void Init(stack* s)
{
	s->a = new int[s->capacity];
	s->num = 0;
}

void expan(stack* s)
{
	int *a = new int[s->capacity * 2];
	for (int i = 0; i < s->num; i++)
	{
		a[i] = s->a[i];
	}
	s->capacity *= 2;
}

bool empty(stack* s)
{
	if (s->num == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
int push(stack* s, int key)
{
	if (s->num == s->capacity)
	{
		expan(s);
	}
	s->a[s->num++] = key;
	return key;
}

bool top(stack* s,int& ret)
{
	if (!empty(s))
	{
		ret= s->a[s->num - 1];
	}
	else
	{
		return false;
	}
	return true;
}

bool pop(stack* s, int& ret)
{
	if (!empty(s))
	{
		ret = s->a[s->num - 1];
		s->num--;
	}
	else
	{
		return false;
	}
	return true;
}